import { Controller } from "egg";
import helper from "../helper";

export default class SecurityController extends Controller {
  async login() {
    const { ctx } = this;

    await ctx.model.User.create({
      name: "zs"
    });

    const users = await ctx.model.User.findAll({
      where: {
        id: 1
      }
    });
    console.log(users);

    const jwtToken = ctx.app.jwt.sign({ username: "guest" }, ctx.app.config.jwt.secret, {
      expiresIn: "10h"
    });
    ctx.cookies.set(ctx.app.config.jwt.secret_key, jwtToken);
    ctx.body = helper.success("登录成功");
    ctx.status = 200;
  }
}
